package com.ruoyi.business.controller;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusClinderGate;
import com.ruoyi.business.service.IBusClinderGateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 缸闸井台账Controller
 * 
 * @author oyh
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/business/gate")
public class BusClinderGateController extends BaseController
{
    @Autowired
    private IBusClinderGateService busClinderGateService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询缸闸井台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:gate:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusClinderGate busClinderGate)
    {
        startPage();
        List<BusClinderGate> list = busClinderGateService.selectBusClinderGateList(busClinderGate);

        return getDataTable(list);
    }

    /**
     * 导出缸闸井台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:gate:export')")
    @Log(title = "缸闸井台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusClinderGate busClinderGate)
    {
        List<BusClinderGate> list = busClinderGateService.selectBusClinderGateList(busClinderGate);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusClinderGate> util = new ExcelUtil<BusClinderGate>(BusClinderGate.class);
        util.exportExcel(response, list, "缸闸井台账数据");
    }

    /**
     * 获取缸闸井台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:gate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busClinderGateService.selectBusClinderGateById(id));
    }

    /**
     * 新增缸闸井台账
     */
    @PreAuthorize("@ss.hasPermi('business:gate:add')")
    @Log(title = "缸闸井台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusClinderGate busClinderGate)
    {
        return toAjax(busClinderGateService.insertBusClinderGate(busClinderGate));
    }

    /**
     * 修改缸闸井台账
     */
    @PreAuthorize("@ss.hasPermi('business:gate:edit')")
    @Log(title = "缸闸井台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusClinderGate busClinderGate)
    {
        return toAjax(busClinderGateService.updateBusClinderGate(busClinderGate));
    }

    /**
     * 删除缸闸井台账
     */
    @PreAuthorize("@ss.hasPermi('business:gate:remove')")
    @Log(title = "缸闸井台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busClinderGateService.deleteBusClinderGateByIds(ids));
    }
}
